package com.jinxi.sign.mode.single;


/**
 * 双重校验
 */
public class LazyDoubCheckSingleton {

    private volatile static LazyDoubCheckSingleton lazy = null;

    private LazyDoubCheckSingleton() {

    }

    public static LazyDoubCheckSingleton getInstance() {
        //是否要阻塞
        if (lazy == null) {
            synchronized (LazyDoubCheckSingleton.class) {
                //是否创建是咧
                if (lazy == null) {
                    lazy = new LazyDoubCheckSingleton();
                    //CPU执行的时候会转化成jvm指令
                    // TODO //指令重排序问题   volatile
                    //1、分配内存给这个对象
                    //2、初始化对象
                    //3、将初始化好的对象和内存地址建立关联，赋值
                    //4、用户初次访问

                }
            }
        }
        return lazy;
    }

}
